﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Navigation;

namespace WpfTester
{
    /// <summary>
    /// Interaction logic for AssemblyInformationDialog.xaml
    /// </summary>
    public partial class AssemblyInformationDialog : Window
    {
        public AssemblyInformationDialog()
        {
            InitializeComponent();

            Version.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(2 /* fieldCount */);

            DataContext = new List<GridRow>
            {
                new GridRow("AsseasdfmblyName", "MyAssemblyName"),
                new GridRow("Fullsadfy Qualified Name", "MyAssemblyName, "),
                new GridRow("Verssdfion", "1.2.0.0"),
                new GridRow("Cultdfsadfure", "neutral"),
                new GridRow("Publsadfisdfc Key Token", "Public Key"),
                new GridRow("AssesdfmblyName", "MyAssemblyName"),
                new GridRow("Fully Qualified Name", "MyAssemblyName, "),
            };
        }

        private void HyperlinkRequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(e.Uri.ToString());
        }

        [DllImport("user32.dll")]
        static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

        protected override void OnSourceInitialized(EventArgs e)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            SetWindowLong(hwnd, -16,
                GetWindowLong(hwnd, -16) & (0xFFFFFFFF ^ 0x80000));

            base.OnSourceInitialized(e);
        }

        internal struct GridRow
        {
            public GridRow(string key, string value)
                : this()
            {
                Name = key;
                Value = value;
            }

            public string Name { get; private set; }
            public string Value { get; private set; }
        }
    }
}
